package com.ryder.petmatediarybackend.module.pet.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ryder.petmatediarybackend.common.response.Result;
import com.ryder.petmatediarybackend.module.pet.entity.SysPetTagLibrary;
import com.ryder.petmatediarybackend.module.pet.service.SysPetTagLibraryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：系统宠物标签库 Controller
 *
 * @author Ryder
 * @version 1.0
 * @since 1.0
 * 更新日期: 2025-10-30 21:18:00
 */
@Slf4j
@Tag(name = "宠物标签库管理", description = "宠物标签库相关接口")
@RestController
@RequestMapping("/pet/tag-library")
@RequiredArgsConstructor
public class SysPetTagLibraryController {

    private final SysPetTagLibraryService tagLibraryService;

    @Operation(summary = "获取所有启用的标签", description = "获取所有状态为启用的宠物标签（用于前端选择）")
    @GetMapping("/list")
    public Result<List<SysPetTagLibrary>> getEnabledTags() {
        log.info("[标签库] 执行获取启用标签列表, 方法=getEnabledTags");
        
        LambdaQueryWrapper<SysPetTagLibrary> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysPetTagLibrary::getStatus, 1) // 只查询启用的标签
                .orderByAsc(SysPetTagLibrary::getSortOrder) // 按排序序号升序
                .orderByAsc(SysPetTagLibrary::getCreateTime); // 相同排序序号按创建时间升序
        
        List<SysPetTagLibrary> tagList = tagLibraryService.list(wrapper);
        log.info("[标签库] 获取启用标签列表成功, 数量={}", tagList.size());
        
        return Result.ok(tagList);
    }

    @Operation(summary = "根据标签类型获取标签", description = "根据标签类型获取启用的标签（1=性格 2=爱好 3=禁忌 4=精神状态）")
    @GetMapping("/list/{tagType}")
    public Result<List<SysPetTagLibrary>> getTagsByType(@PathVariable Integer tagType) {
        log.info("[标签库] 执行获取指定类型标签, 方法=getTagsByType, 标签类型={}", tagType);
        
        LambdaQueryWrapper<SysPetTagLibrary> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysPetTagLibrary::getStatus, 1) // 只查询启用的标签
                .eq(SysPetTagLibrary::getTagType, tagType) // 指定标签类型
                .orderByAsc(SysPetTagLibrary::getSortOrder)
                .orderByAsc(SysPetTagLibrary::getCreateTime);
        
        List<SysPetTagLibrary> tagList = tagLibraryService.list(wrapper);
        log.info("[标签库] 获取指定类型标签成功, 标签类型={}, 数量={}", tagType, tagList.size());
        
        return Result.ok(tagList);
    }
}
